#!/bin/bash

CheckProcess(){

if [ "$1" = "" ];
then
        return 1
fi

PROCESS_NUM=`ps -ef | grep "$1" | grep -v "grep" | wc -l`
if [ $PROCESS_NUM -eq 1 ];
then
        return 1
else
        return 0
fi
}

main(){
#------------------------------------------------------------------------------------------------------------
CheckProcess "vgcEnmAlarm.jar"
Check_RET=$?
if [ $Check_RET -eq 0 ];
then
        echo "lost-vgcEnmAlarm.jar"
        sed -i '/17.168.145.206/d' /root/.ssh/known_hosts
        ALARMSH_PORT=`ps -ef |grep vgcEnmAlarm.sh |grep -w 'vgcEnmAlarm.sh'|grep -v 'grep'|awk '{print $2}'`
        kill -9 $ALARMSH_PORT
        SSHOSS_PORT=`ps -ef |grep 5genm|grep -w '5genm'|grep -v 'grep'|awk '{print $2}'`
        kill -9 $SSHOSS_PORT
        nohup java -jar /opt/Ericsson/core/bin/vgcEnmAlarm.jar >/dev/null 2>&1 &
        sleep 10
else
        echo "ok"
fi
#-------------------------------------------------------------------------------------------------------------
CheckProcess "vgcEnmAlarm.sh"
Check_RET=$?
if [ $Check_RET -eq 0 ];
then
        echo "lost-vgcEnmAlarm.sh"
        sed -i '/17.168.145.206/d' /root/.ssh/known_hosts
        ALARMJAR_PORT=`ps -ef |grep vgcEnmAlarm.jar |grep -w 'vgcEnmAlarm.jar'|grep -v 'grep'|awk '{print $2}'`
        kill -9 $ALARMJAR_PORT
        SSHOSS_PORT=`ps -ef |grep 5genm |grep -w '5genm'|grep -v 'grep'|awk '{print $2}'`
        kill -9 $SSHOSS_PORT
        nohup java -jar /opt/Ericsson/core/bin/vgcEnmAlarm.jar >/dev/null 2>&1 &
        sleep 10
else
        echo "ok"
fi
#-------------------------------------------------------------------------------------------------------------
CheckProcess "5genm"
Check_RET=$?
if [ $Check_RET -eq 0 ];
then
        echo "lost-5genm"
        sed -i '/17.168.145.206/d' /root/.ssh/known_hosts
        ALARMJAR_PORT=`ps -ef |grep vgcEnmAlarm.jar |grep -w 'vgcEnmAlarm.jar'|grep -v 'grep'|awk '{print $2}'`
        kill -9 $ALARMJAR_PORT
        ALARMSH_PORT=`ps -ef |grep vgcEnmAlarm.sh |grep -w 'vgcEnmAlarm.sh'|grep -v 'grep'|awk '{print $2}'`
        kill -9 $ALARMSH_PORT
        nohup java -jar /opt/Ericsson/core/bin/vgcEnmAlarm.jar >/dev/null 2>&1 &
        sleep 10
else
        echo "ok"
fi
}
main